package com.mokairui.basic.demo4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author Mokairui
 * @Description
 * @Since 2021/6/28
 */
public class ServerRunnableTarget implements Runnable {

    private Socket socket;

    public ServerRunnableTarget(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            // 处理接受到的客户端socket通信需求
            InputStream inputStream = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String msg;
            while ((msg = br.readLine()) != null) {
                System.out.println("服务端接受到：" + msg);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
